package com.lb.shopguide.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lb.shopguide.R;
import com.lb.shopguide.entity.market.ActivityAdviceBean;
import com.lb.shopguide.util.pic.ImageLoaderUtils;

import java.util.List;

public class AdapterActivityAdvice extends BaseQuickAdapter<ActivityAdviceBean, BaseViewHolder> {
    public AdapterActivityAdvice(int layoutResId, @Nullable List<ActivityAdviceBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final ActivityAdviceBean item) {
        View view = helper.itemView;
        ImageView ivAdvicePic = view.findViewById(R.id.iv_advice_pic);
        TextView tvAdviceTime = view.findViewById(R.id.tv_advice_time);
        TextView tvAdviceName = view.findViewById(R.id.tv_advice_name);
        TextView tvAdviceDesc = view.findViewById(R.id.tv_advice_desc);
        TextView tvUseAdvice = view.findViewById(R.id.tv_use_advice);
        TextView tvShopName = view.findViewById(R.id.tv_shop_name);

        TextView tvTempName = view.findViewById(R.id.tv_temp_name);
        TextView tvTempTitle = view.findViewById(R.id.tv_temp_title);
        ImageView ivIcon = view.findViewById(R.id.iv_temp_icon);

        tvAdviceDesc.setText(item.getTipDesc());
        tvAdviceName.setText(item.getTipTitle());
        tvAdviceTime.setText(item.getCreateTime());
        tvTempName.setText(item.getTemplateName());
        tvTempTitle.setText(item.getTemplateDesc());
        tvShopName.setText(item.getStoreName());
        ImageLoaderUtils.displayCircle(mContext, ivIcon, item.getTemplatePicUrl());
        ImageLoaderUtils.displayCircle(mContext, ivAdvicePic, item.getStoreLogoUrl());
        tvUseAdvice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnUseAdviceListener != null) {
                    mOnUseAdviceListener.onUseAdvice(item.getStoreCode(), item.getTemplateCode(), item.getTemplateName());
                }
            }
        });
    }

    public interface OnUseAdviceListener {
        void onUseAdvice(String storeCode, String templateCode, String templateName);
    }

    private OnUseAdviceListener mOnUseAdviceListener;

    public void setOnUseAdviceListener(OnUseAdviceListener listener) {
        mOnUseAdviceListener = listener;
    }
}
